// 项目文档
using('messager', function () {
    $.messager.progress({
        title: '提示',
        text: '系统加载中，请稍后....'
    });
    page_init();
});

var projectfilestable;
var Project_Box;

function page_init(){
	using(["layout",'panel', 'dialog','datagrid','accordion','linkbutton','textbox','combobox',"datebox","form"], function () {
        $.messager.progress('close');
		$("#projectfileslayout").layout({fit:true});
		//$.parser.parse(".easyui-panel");
		table_init();
		ProjectBox();
		
		$("#QueryBtn").linkbutton({
			onClick:function(){
				projectfilestable.datagrid({
					queryParams:{
						QueryCustomerId:$("#QueryCustomerId").textbox("getValue"),
						QueryProjectNameId:$("#QueryProjectNameId").textbox("getValue"),
						QueryProjectDateStart:$("#QueryProjectDateStart").datebox("getValue"),
						QueryProjectDateEnd:$("#QueryProjectDateEnd").datebox("getValue")
						}
					});
			}
			});
		
		$("#CustomerId").combobox({
			    url:webpath+"ProjectFiles/getCustomer",
				valueField:"clientinfo_uuid",
				textField:"client_name",
				required:true,
				onSelect: function(rec){
					$('#ProjectNameId').combobox("clear");
            		var url = webpath+"ProjectFiles/getProject?uuid="+rec.clientinfo_uuid;
            		$('#ProjectNameId').combobox('reload', url);
        		},
				icons: [{
					iconCls:'icon-add',
					handler: function(e){
					parent.addTab({ title: "客户(项目)管理", url: webpath+"Customer" });
				}
				}]
			});
		
		$("#ProjectNameId").combobox(
			{
				valueField:"proinfo_uuid",
				textField:"pro_name",
				required:true,
				icons: [{
					iconCls:'icon-add',
					handler: function(e){
					parent.addTab({ title: "客户(项目)管理", url: webpath+"Customer" });
					}
				}]
			}
		);
		
		$("#engineer_name").textbox({
			required:true
			});
		$("#pro_address").textbox({
			required:true
			});
		
		$("#ProjectDateStart").datebox({
			required:true,
			validType:"checkDate"
			});
		$("#ProjectDateEnd").datebox({
			validType:"checkDate"
			});
		$("#ProjectDetectionDate").datebox({
			validType:"checkDate"
			});
		$("#ProjectReportDate").datebox({
			validType:"checkDate"
			});
		
	});
}

function table_init()
{
	projectfilestable=$("#projectfilestable").datagrid({
		title:"项目档案信息",
			method:"post",
			url:webpath+"ProjectFiles/QueryProjectFiles",
			//queryParams:{customeruser:""},
			singleSelect:true,
			rownumbers:true,
			fit:true,
			fitColumns:true,
			pageSize : 10,
			pageList : [ 10,15, 25, 35, 45, 55,65,100],
			nowrap : false,
			pagination:true,
			showFooter:true,
			//iconCls:'icon-man',
			columns:[[
				{field:'proarc_uuid',hidden:true},
				{field:'proarc_number',title:'项目档案编号',fixed:true},
				{field:'client_name',title:'客户名称',fixed:true},
				{field:'pro_name',title:'项目名称',fixed:true},
				{field:'procha_name',title:'项目负责人',fixed:true},
				//{field:'engineer_name',title:'工程名称',fixed:true},
				//{field:'pro_address',title:'工程地址',fixed:true},
				{field:'inv_category',title:'发票类别',fixed:true},
				{field:'probegin_date',title:'项目起时间',fixed:true},
				{field:'proend_date',title:'项目止时间',fixed:true},
				{field:'procheck_date',title:'检测时间',fixed:true},
				{field:'proreport_date',title:'报告时间',fixed:true}
        	]],toolbar: [
			{
			iconCls: 'icon-add',
			text:"添加新档案",
			handler: function(){
				$(Project_Box).dialog("open");
				}
			}]
		});
}

function ProjectBox()
{
	Project_Box=$("#ProjectBox").dialog({
		    title: '新建项目档案信息',
			width: 700,
			height: 350,
			closed: true,
			cache: false,
			modal: true,
			onClose:function(){
				$("#NewProjectFiles").form("clear");
			},
			buttons:[{
				text:'保存',
				iconCls:'icon-save',
				handler:function(){
					$.messager.confirm('确认','确认新建项目档案信息吗?',function(r){
						if(r){
							$('#NewProjectFiles').submit();
							}
						});
					}
			},{
				text:'关闭',
				iconCls:'icon-no',
				handler:function(){Project_Box.dialog("close");}
			}]
		});
	$("#ProjectBox").css("visibility","visible");
	
	
	$("#NewProjectFiles").form({
    url:webpath+"ProjectFiles/AddProjectFile",
    onSubmit: function(){
		var val= $(this).form('enableValidation').form('validate');
		if(val)
		{
			$.messager.progress();
		}
		return val;
		},
		success:function(data){
			var json=eval('(' + data + ')')
			$.messager.progress('close');
			Project_Box.dialog("close");
			$.messager.alert('提示', json.message, 'info');
			projectfilestable.datagrid("reload");
		}
	});
}